predictCL = function(plik){
       cl<- read.table("CL_2008_2009.csv", 
                  header=FALSE, sep=","
                  , colClass=c("character", 
                               "numeric"))
       IndexCl<-as.Date(cl$V1, "%Y%m%d")
       dane<-xts(cl$V2, IndexCl)
       T = length(dane)
       returns = diff(dane)/lag(dane)
       forecast = array(NA, T)
       for (i in 200:T){         
         forecast[i] = (1.0011 + 0.08*as.numeric(returns[i-25])+ 0.02*as.numeric(returns[i-24]) - 0.04*as.numeric(returns[i-21]) + 0.04*as.numeric(returns[i-20])- 0.055*as.numeric(returns[i-17]) + 0.135*as.numeric(returns[i-15]) + 0.02*as.numeric(returns[i-12])+ 0.075*as.numeric(returns[i-12])- 0.04*as.numeric(returns[i-11]) -0.021*as.numeric(returns[i-10])
         -0.02*as.numeric(returns[i-7])  +0.03*as.numeric(returns[i-6])+ 0.015*as.numeric(returns[i-5])+0.03*as.numeric(returns[i-4])- 0.02*as.numeric(returns[i-3]) + 0.03*as.numeric(returns[i-2]) -0.025*as.numeric(returns[i-1])  ) * dane[i-1]
       }
       return(cbind(dane,forecast))
   }
## U?yli?my modelu regresji liniowej, ze sta?ymi wsp??czynnikami. 
## Dla danych z roku 2008 uzyskali?mu popraw? w stosunku do Random Walk o ponad 3.2%. 

d1 = "CL_2008_2009.csv"
f1 = predictCL(d1)
length(f1)
RWE1 = sum(abs(diff(f1[, 1]))[200:505])
FE1 = mean(abs(f1[200:505, 1]-f1[200:505, 2]))
print(RWE1)
print(FE1)
print(FE1/RWE1)
plot(f1[, 1], type = "l")
lines(f1[, 2], col = "red")

Q = read.table(d1, header=FALSE, sep=",")
index=as.Date(Q$V1, "%Y%m%d")